<template>
	<view class="page">
		<view class="donghua-box">
			<view class="content">
				<view class="logo">
					<image src="/static/img/logo.png" mode=""></image>
				</view>
				<view class="title-box">互成壹家</view>
			</view>
			<view class="bottom-text">BECOME ONE FAMILY WITH EACH OTHER</view>
		</view>
		<view class="top-line">
			<view class="bg1"></view>
			<view class="bg2"></view>
			<view class="bg3"></view>
			<view class="bg4"></view>
			<view class="bg5"></view>
			<view class="top-line-title">互成壹家</view>
			<view class="top-line-text">BECOME ONE FAMILY WITH EACH OTHER</view>
		</view>
		<view class="login-line">
			<view class="wx-login-logo">
				<image src="/static/img/weixin.png" mode=""></image>
				<!-- <img src="/static/img/weixin.png" /> -->
			</view>
			<view class="wx-login-btn">
				<view class="wx-button" @click="clickLoginBtn" :style="{backgroundColor: btnColor}">微信快捷登录</view>
			</view>
		</view>
	</view>
</template>

<script>
import { user } from '../../server/user.js';

export default {
	data() {
		return {
			btnColor: 'rgb(41, 197, 70)'
		}
	},
	methods: {
		async clickLoginBtn() {
			this.btnColor = 'rgb(35, 161, 53)';
			uni.showLoading({
			    title: '登录中...',
			    mask: true
			});
			setTimeout(() => {
				this.btnColor = 'rgb(41, 197, 70)';
			}, 100);
			let res = await user.wxLoginBycode();
			if (res.success) {
				uni.hideLoading();
				uni.switchTab({
					url: '/pages/main/main'
				});
			} else {
				// 登录失败的时候需要完成的事情
				uni.showToast({
					icon: 'error',
					title: '登录失败，请检查网络重新登录'
				})
			}
		},
	}
}
</script>

<style>
/*
 * 定义一个淡出动画
 */
 @keyframes fadeOut {
    0% {
        opacity: 1;
        /* transform: translateY(-50%); */
    }
    100% {
        transform: translateY(-10%);
        opacity: 0;
    }
}

/*
 * 定义一个淡入动画
 */
 @keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.page {
	--logo-size: 50vmin;
    width: 100vw;
    height: 100vh;
    /* background-color: #f5f5f5; */
    position: relative;
    overflow: hidden;
    user-select: auto;
}

.donghua-box {
    width: 100vw;
    height: 100vh;
    position: relative;
    animation: fadeOut 1s ease-out 1s 1 normal both;
}

.content {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* 在此处应用淡出动画 */
    /* animation: fadeOut 1s ease-in-out forwards; */
}
.logo {
    width: var(--logo-size);
    height: var(--logo-size);
}
.logo image {
    width: 100%;
    height: 100%;
}
.title-box {
    font-size: 12vmin;
    font-family: '华文新魏';
}
.bottom-text {
    width: 100vw;
    text-align: center;
    font-size: 3vmin;
    color: rgb(106, 106, 106);
    position: absolute;
    top: 80%;
    transform: translateY(-50%);
    /* animation: fadeOut 1s ease-out 1s 1 normal both; */
}

.top-line {
    position: absolute;
    top: 0;
    width: 100vw;
    height: 50vmin;
    /* background-color: rgb(233, 244, 255); */
    /* 渐变背景 */
    background: linear-gradient(to bottom, rgb(233, 244, 255), rgb(249, 252, 255));
    animation: fadeIn 1s ease-out 1s 1 normal both;
}

.bg1, .bg2, .bg3, .bg4, .bg5 {
    position: absolute;
    background: linear-gradient(to right, rgb(219, 237, 253), rgb(233, 242, 252));
    border-radius: 1vmin;
}

.bg1 {
    top: 10%;
    left: 60%;
    width: 18vmin;
    height: 10vmin;
}

.bg2 {
    top: 50%;
    left: 70%;
    width: 34vmin;
    height: 19vmin;
}

.bg3 {
    top: 70%;
    left: 20%;
    width: 15vmin;
    height: 7vmin;
}

.bg4 {
    top: 80%;
    left: 0%;
    width: 30vmin;
    height: 7vmin;
}

.bg5 {
    top: 30%;
    left: 10%;
    width: 40vmin;
    height: 10vmin;
}

.top-line-title {
    font-size: 8vmin;
    font-weight: 900;
    position: absolute;
    top: 35%;
    left: 10vmin;
}

.top-line-title::after {
    margin-left: 3%;
    padding: 2% 7%;
    content: "欢迎到来";
    width: 5em;
    display: block;
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    font-size: 5vmin;
    text-align: center;
    color: #fff;
    background-color: rgb(23, 133, 199);
    border-radius: 1vmin;
}

.top-line-text {
    font-size: 2.5vmin;
    position: absolute;
    top: 65%;
    left: 10vmin;
}

.login-line {
    width: 100vw;
    min-height: 100vh;
    background-color: #fff;
    position: absolute;
    top: 45vmin;
    border-radius: 5vmin 5vmin 5vmin 5vmin;
    animation: fadeIn 1s ease-out 1s 1 normal both;
    box-shadow: 0 0 3vmin 0vmin rgba(0, 0, 0, 0.3);
}

.wx-login-logo {
    width: 100vw;
    height: 20vmin;
    margin-top: 10vmin;
    text-align: center;
}

.wx-login-logo image {
	width: 20vmin;
    height: 20vmin;
}

.wx-login-btn {
    width: 100vw;
    text-align: center;
}

.wx-button {
    box-sizing: content-box;
    width: 30vmin;
    height: 5vmin;
    line-height: 5vmin;
    margin: 10vmin auto;
    padding: 2vmin 10vmin;
    border-radius: 2vmin;
    background-color: rgb(41, 197, 70);
    border: 0px solid #ccc;
    font-size: 4vmin;
    color: #fff;
    /* cursor: pointer; */
    font-weight: 900;
}
</style>
